package com.zw.controller;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zw.dao.asdasd;
import com.zw.entity.Commodity;
import com.zw.entity.User;

import com.zw.service.CommodityService;
import com.zw.service.UserService;
import com.zw.service.impl.ShopImpl;

@Controller
public class LoginController{

	private Logger log = LogManager.getLogger(LoginController.class);


	@Autowired
	private CommodityService commodityService;

	@Autowired
	private UserService uService;
	
	@Autowired
	private ShopImpl shopImpl;
	@Autowired
	private KafkaTemplate<String, Object> template;



	@RequestMapping("/")
	public String login(){
		log.info("进入登入页面");
		asdasd asdasd=new asdasd();
		System.out.println(shopImpl.show("走了走了-.-凉了"));
		asdasd.showString("shut up");
		template.send("my","show","1111");
		return "login";
	}
	
	@KafkaListener(id="show",topics="my")
	public void myreplicatedtopic(ConsumerRecord<?, ?> cr) throws Exception{
		System.out.println(cr.value());
	}

	@RequestMapping("/login")
	@ResponseBody
	public String login1(User u,HttpServletRequest request) throws IOException{
		User user=uService.selectUser(u);
		if(null!=user){
			log.info("登入成功");
			HttpSession session=request.getSession();
			session.setAttribute("user", user);
			return "success";
		}
		return "error";
	}



	
}
